package com.jianggujin.redis.dialog;

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Toolkit;

import javax.swing.JDialog;

import com.jianggujin.redis.util.SwingUtils;

public abstract class AbstractDialog extends JDialog {
    public AbstractDialog(Frame parent) {
        super(parent, true);
        init();
    }

    public AbstractDialog(Dialog parent) {
        super(parent, true);
        init();
    }

    private void init() {
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        initComponent();
        SwingUtils.resizeFont(this);
        initDialog();
    }

    protected abstract void initComponent();

    protected void initDialog() {
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        // 设置窗体在显示器居中显示
        this.setBounds((width - getWidth()) / 2, (height - getHeight()) / 2, getWidth(), getHeight());
    }
}
